package com.yds.bluetooth.views

import android.bluetooth.BluetoothDevice
import java.util.*

/**
 * 临时数据
 */
object TempData {

    // 临时设备列表
    private var mListDevices = Collections.synchronizedList(mutableListOf<BluetoothDevice>())

    fun putDevices(list: List<BluetoothDevice>) {
        synchronized(mListDevices) {
            if (mListDevices.isNotEmpty()) {
                mListDevices.clear()
            }
            mListDevices.addAll(list)
        }
    }

    fun getHistoryDevices(): List<BluetoothDevice> {
        synchronized(mListDevices) {
            return mListDevices
        }
    }

    // 连接设备状态
    private var connectState = false

    fun setDeviceConnectState(state: Boolean) {
        synchronized(connectState) {
            this.connectState = state
        }
    }

    fun getDeviceConnectState(): Boolean {
        synchronized(connectState) {
            return connectState
        }
    }

    // 已连接设备mac地址
    private var connectDeviceMac = ""

    fun setConnectDeviceMac(mac: String) {
        synchronized(connectDeviceMac) {
            this.connectDeviceMac = mac
        }
    }

    fun getConnectDeviceMac(): String {
        synchronized(connectDeviceMac) {
            return connectDeviceMac
        }
    }

    // 清空数据
    fun clear() {
        this.mListDevices.clear()
        this.connectDeviceMac = ""
        this.connectState = false
    }
}